import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 引入样式
import './assets/css/init.css'
import './assets/iconfont/iconfont.css'

// 引用组件
import PageView from './components/PageView.vue'

const app = createApp(App);
// 注册全局组件

app.component('page-view', PageView);
import PageHeader from "@/components/PageHeader.vue";
app.component('page-header', PageHeader);

// 注册vant中的全局插件
import { Toast, Lazyload } from "vant"

// 设置Toast在loading时的位置
Toast.setDefaultOptions("loading", { forbidClick: true });    // 加载中

app.use(Toast);

// 注册懒加载插件
app.use(Lazyload, {
    lazyComponent: true,
    //图片预加载时的动画
    loading: require('./assets/imge/loading.gif'),
    //预加载没获取到
    error: require('./assets/imge/error.jpeg')
});

// 写入mixinx,在全局挂载一个baseURL，写入长按指令
app.mixin({
    data() {
        return {
            BaseURL: "http://home.softeem.xin:9544",
        }
    },
}).directive('longpress', {
    //混入一个longpress长按的指令
    mounted(el, binding, vnode, oldVnode) {
        let timeout = binding.arg || 500;
        let timeId = null;
        el.addEventListener('touchstart', function (e) {
            timeId = setTimeout(function () {
                binding.value.call(vnode.context, e);
            }, timeout);
        }, false);
        el.addEventListener('touchend', function (e) {
            clearTimeout(timeId);
        }, false);
        el.addEventListener('touchmove', function (e) {
            clearTimeout(timeId);
        }, false);
        el.addEventListener('touchcancel', function (e) {
            clearTimeout(timeId);
        }, false);
    }
});



app.use(store).use(router).mount('#app')
